<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="head-title">
        <title>Pending Packing Order| Merlion's ERP System</title>
    </ui:define>

    <ui:define name="content">
        <p:panel id="panel" header="Pending Packing Orders"> 
            <p:ajaxStatus style="width:16px;height:16px;">   
                <f:facet name="start">   
                    <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                </f:facet> 

                <f:facet name="complete">   
                    <h:outputText value="" />   
                </f:facet>   
            </p:ajaxStatus>
            <h:form prependId="false"> 
                <p:dataTable id="packingOrderTable" var="packingOrder" value="#{pendingPackingOrderManagerBean.pendingPackingOrder}" 
                             dynamic="true" paginator="true" rows="10" emptyMessage="No Packing Order Record" selection="#{pendingPackingOrderManagerBean.selectedPackingOrder}" onRowSelectUpdate="display">
                    <p:column selectionMode="single"/>

                    <p:column sortBy="#{packingOrder.id}" filterBy="#{packingOrder.id}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Packing Order ID" /> 
                        </f:facet> 
                        <h:outputText value="#{packingOrder.id}" /> 
                    </p:column> 

                    <p:column sortBy="#{packingOrder.deliveryOrder.id}" filterBy="#{packingOrder.deliveryOrder.id}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Delivery ID" /> 
                        </f:facet> 
                        <h:outputText value="#{packingOrder.deliveryOrder.id}" /> 
                    </p:column>

                    <p:column sortBy="#{packingOrder.packingDate}" filterBy="#{packingOrder.packingDate}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Packing Date" /> 
                        </f:facet> 
                        <h:outputText value="#{packingOrder.packingDate}" /> 
                    </p:column>

                    <p:column sortBy="#{packingOrder.deliveryOrder.deliveryState}" filterBy="#{packingOrder.deliveryOrder.deliveryState}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Delivery State" /> 
                        </f:facet> 
                        <h:outputText value="#{packingOrder.deliveryOrder.deliveryState}" /> 
                    </p:column>

                    <p:column sortBy="#{packingOrder.packingState}" filterBy="#{packingOrder.packingState}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Packing State" /> 
                        </f:facet> 
                        <h:outputText value="#{packingOrder.packingState}" /> 
                    </p:column>

                    <f:facet name="footer">  
                        <p:commandButton value="View" image="ui-icon ui-icon-search" update="display1 display2" oncomplete="packingOrderViewDialog.show()"/>
                        <p:commandButton value="Process Packing Order" update="display3 display4" oncomplete="processPackingOrderDialog.show()"/> 
                    </f:facet>

                </p:dataTable>

                <p:dialog header="Packing Order Detail" widgetVar="packingOrderViewDialog" width="450" height="300" resizable="true" showEffect="clip" hideEffect="fold">
                    <h:panelGrid id="display1" columns="2" cellpadding="5">
                        <h:outputText value="Packing Order ID:"/>
                        <h:outputText value="#{pendingPackingOrderManagerBean.selectedPackingOrder.id}"/>
                    </h:panelGrid>

                    <p:dataTable var="productLine" value="#{pendingPackingOrderManagerBean.selectedPackingOrder.deliveryOrder.productLines}" dynamic="true" paginator="true" emptyMessage="No Product Type" id="display2">
                        <p:column sortBy="#{productLine.product.productType}">
                            <f:facet name="header">
                                <h:outputText value="Product Type"/>
                            </f:facet>
                            <h:outputText value="#{productLine.product.productType}"/>
                        </p:column>

                        <p:column sortBy="#{productLine.quantity}">
                            <f:facet name="header">
                                <h:outputText value="Quantity"/>
                            </f:facet>
                            <h:outputText value="#{productLine.quantity}"/>
                        </p:column>
                    </p:dataTable>
                </p:dialog>

                <p:dialog header="Packing Order Detail" widgetVar="processPackingOrderDialog" width="450" height="300" resizable="true" showEffect="clip" hideEffect="fold">
                    <h:panelGrid id="display3" columns="2" cellpadding="5">
                        <h:outputText value="Packing Order ID:"/>
                        <h:outputText value="#{pendingPackingOrderManagerBean.selectedPackingOrder.id}"/>
                    </h:panelGrid>

                    <p:dataTable var="productLine" value="#{pendingPackingOrderManagerBean.selectedPackingOrder.deliveryOrder.productLines}" dynamic="true" paginator="true" emptyMessage="No Product Type" id="display4">
                        <p:column sortBy="#{productLine.product.productType}">
                            <f:facet name="header">
                                <h:outputText value="Product Type"/>
                            </f:facet>
                            <h:outputText value="#{productLine.product.productType}"/>
                        </p:column>

                        <p:column sortBy="#{productLine.quantity}">
                            <f:facet name="header">
                                <h:outputText value="Quantity"/>
                            </f:facet>
                            <h:outputText value="#{productLine.quantity}"/>
                        </p:column>
                    </p:dataTable>

                    <p:spacer height="35"/>

                    <p:commandButton value="Confirm Process"  actionListener="#{pendingPackingOrderManagerBean.processPackingOrder(event)}" update="packingOrderTable" oncomplete="processPackingOrderDialog.hide()">
                        <f:attribute name="selectedPackingOrder" value="#{packingOrder}"/>
                    </p:commandButton>
                    <p:commandButton value="Cancel" image="ui-icon ui-icon-close" onclick="processPackingOrderDialog.hide()"/>
                    <p:messages />

                </p:dialog>

            </h:form>
        </p:panel>
    </ui:define>

</ui:composition>
